import Taro from '@tarojs/taro'
import app from '../../../main.js'
let myJs = {
    getData: function() {
        this.state = {
            case_detail: {
                type: '',
                relate_id: '',
                labels: '',
                patient_name: '',
                gender: '',
                birthday: '',
                phone: '',
                province: '',
                city: '',
                occupation: '',
                marry_status: '',
                visit_at: '',
                main_suit: '',
                present_illness: '',
                manxingbingshi: '',
                yanwaishangshi: '',
                quguangzhuangtai: '',
                yanbusoushushi: '',
                yanbingshi: '',
                chuanranbingshi: '',
                guominshi: '',
                family_illness: '',
                zhenduan: '',
                zhiliao: '',
                tiwen: '',
                huxi: '',
                maibo: '',
                xueya_shousuo: '',
                xueya_shuzhang: '',
                tizhong: '',
                report_images: '',
                physical_images: '',
                case_images: '',
                diagnosis: '',
                cure: '',
            },
            left_eye: {
                id: '',
                case_detail_id: '',
                luoyanshili: '',
                jiaozhengshili: '',
                guangdingwei: '',
                sejue: '',
                yanjian: '',
                jiemao: '',
                yanwei: '',
                yanqiu: '',
                jiemo: '',
                leidaochongxi: '',
                nurou: '',
                jiaomo: '',
                qianfang: '',
                hongmo: '',
                tongkong: '',
                jingzhuangti: '',
                boliti: '',
                yandi: '',
                yanya: '',
                abchao: '',
                gonggao: '',
                neipixibao: '',
                guangjiaodu: '',
            },
            right_eye: {
                id: '',
                case_detail_id: '',
                luoyanshili: '',
                jiaozhengshili: '',
                guangdingwei: '',
                sejue: '',
                yanjian: '',
                jiemao: '',
                yanwei: '',
                yanqiu: '',
                jiemo: '',
                leidaochongxi: '',
                nurou: '',
                jiaomo: '',
                qianfang: '',
                hongmo: '',
                tongkong: '',
                jingzhuangti: '',
                boliti: '',
                yandi: '',
                yanya: '',
                abchao: '',
                gonggao: '',
                neipixibao: '',
                guangjiaodu: '',
            },
        };
        return this.state;
    },
    createCaseDetail() {
        var me = this;
        var data = me.state.case_detail;
        var flag = true;
        if(me.beforeCreateCaseDetail) {
            flag = me.beforeCreateCaseDetail(data);
        }
        if(flag) {
            app.post("api/case_details/create", data, function(res) {
                if(me.afterCreateCaseDetail) {
                    me.afterCreateCaseDetail(res);
                }
            });
        }
    },
    createLeftEye() {
        var me = this;
        var data = me.state.left_eye;
        var flag = true;
        if(me.beforeCreateLeftEye) {
            flag = me.beforeCreateLeftEye(data);
        }
        if(flag) {
            app.post("api/left_eyes/create", data, function(res) {
                if(me.afterCreateLeftEye) {
                    me.afterCreateLeftEye(res);
                }
            });
        }
    },
    createRightEye() {
        var me = this;
        var data = me.state.right_eye;
        var flag = true;
        if(me.beforeCreateRightEye) {
            flag = me.beforeCreateRightEye(data);
        }
        if(flag) {
            app.post("api/right_eyes/create", data, function(res) {
                if(me.afterCreateRightEye) {
                    me.afterCreateRightEye(res);
                }
            });
        }
    },
    componentWillMount () {
        if(this.init) {
            this.init();
        }
    },
    navigateTo(url) {
        app.navigateTo(url);
    },
    handleChange(name, v) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = v;
        this.setState({n: temp[names[i]]});
    },
    handleTextareaChange(name, e) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = e.target.value;
        this.setState({n: temp[names[i]]});
    },
    redirectTo(url) {
        app.redirectTo(url);
    },
    componentDidMount () {},
    componentWillUnmount () {},
    componentDidHide () {}
}
export default myJs;
